#ifndef QLSLANGUAGEMANAGER_H
#define QLSLANGUAGEMANAGER_H

#include <QObject>
#include <QMutex>
#include <QString>
#include <QStringList>
#include <QTranslator>
#include <QMap>

#include "qls_languages_manager_global.h"

class QLS_LANGUAGES_MANAGER_EXPORT QLsLanguagesManager : public QObject
{
    Q_OBJECT
public:
    explicit QLsLanguagesManager(QObject *parent = nullptr);

    /* 唯一实例 */
    static QLsLanguagesManager &GetInstance();
    /* 销毁实例 */
    static void DestroyInstance();

    /* 刷新本地语言包 */
    void RefreshLocalLangPacks();
    /* 加载语言包
     * 默认语言包文件名为 langPackName.qm
     */
    bool LoadLangPack(const QString &langPackName);
    /* 获取可用语言包列表 */
    QStringList GetLangPacks() const;
    /* 获取当前语言包 */
    QString GetCurrentLangPack() const;
    /// 语言包类型翻译
    static QMap<QString, QString> getLanguagesMap();

private:
    QStringList m_langPacksList;  /* 可用语言包列表 */
    QString m_curLangPack;        /* 当前语言包名 */
    QTranslator *m_curTranslator; /* 当前语言包 */

    static QMap<QString, QString> m_languages_map; ///< 语言包类型翻译

    /* instance */
    static QMutex m_instanceMutex;
    static QLsLanguagesManager *m_instance;
};

#endif // QLSLANGUAGEMANAGER_H
